import Router from 'koa-router';
const router = new Router();
import query from '../utils/query';
router.prefix('/users');

const foo = async (ctx:Router.RouterContext, next:any) => {
    let sql='select * from receipt';
    let data=await query(sql)
    ctx.body = data
};
router.get('/foo', foo);

const bar = async (ctx:Router.RouterContext, next:any) => {
    let {type,name,number,email,special,defaults} :any=ctx.request.body;
    // console.log(ctx.request.body);
    let sql=`insert into receipt(type,name,number,email,special,defaults) values('${type}','${name}','${number}','${email}',${special},${defaults})`   
    let data=await query(sql)
    ctx.body=data;
};
router.post('/bar', bar);
const upd = async (ctx:Router.RouterContext, next:any) => {
    let {id,name,number,email} :any=ctx.request.body;
    console.log(ctx.request.body);
    let sql=`update receipt set name='${name}',number='${number}',email='${email}' where id=${id}`   
    let data=await query(sql)
    ctx.body=data;
};
router.post('/upd', upd);
const del = async (ctx:Router.RouterContext, next:any) => {
    let {id} :any=ctx.request.body;
    let sql=`delete from receipt where id=${id}`   
    let data=await query(sql)
    ctx.body=data;
};
router.post('/del', del);
export default router;